package net.optix.ip.commands
{
	import com.adobe.cairngorm.business.Responder;
	import com.adobe.cairngorm.commands.Command;
	import com.adobe.cairngorm.control.CairngormEvent;
	
	import net.optix.ip.business.*;
	import net.optix.ip.events.ProtectAsSecretEvent;
	import net.optix.ip.model.ModelLocator;
	
	import views.ViewInstance;

	public class ProtectAsSecretCommand implements Command, Responder
	{
		// attributes ============================
		private var model : ModelLocator = ModelLocator.getInstance();


		// functions ============================
		public function execute( event:CairngormEvent ) : void
		{
			var myEvent:ProtectAsSecretEvent = ProtectAsSecretEvent( event );
			
			var delegate:InventionDelegate = new InventionDelegate();     
			delegate.protectAsSecret( this , myEvent.inventionID ,myEvent.clientID);
		}
		
		//----------------------------------------------------------------------------
		public function onResult( event : * = null ) : void
		{
			trace(event.result+"   event");
			var result:int	=	event.result.result;
			var message:String	=	"";
			switch(result)
			{
				case -2:
					message	=	"Access Denied .";
					break;
				case 0:
					message	=	"The email is used,try other";
					break;
				case -1:
					message	=	"Successfully convert the invention into a trade secret";
					break;
				case 1:
					message	=	"Successfully convert the invention into a trade secret";
					model.view	=	0;
					model.view	=	ViewInstance.ViewInventions;
					break;
			}
			model.bSubmit	=	true;
			ViewInstance.showMessage("Result of convert invention into trade secret",message);
		}
		
		//----------------------------------------------------------------------------
		public function onFault( event : * = null ) : void
		{
			ViewInstance.showMessage("Result of convert invention into trade secret","Program error!");
			
			model.bSubmit	=	true;
		}

	}
}